﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using WarOfDev.EF;

namespace WarOfDev.Core.Extention
{
    public enum ButtonStatus
    {
        Disabled,
        Hidden
    }

    public static class HtmlHelperEx
    {
        public static MvcHtmlString ExActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string permissionName, ButtonStatus hidden, User user)
        {
            if (user != null && user.Permissions != null)
            {
                if (user.Permissions.Where(p => p.PermissionName == permissionName).Count() > 0)
                {
                    return LinkExtensions.ActionLink(htmlHelper, linkText, actionName, controllerName);
                }
                else
                {
                    if (hidden == ButtonStatus.Disabled)
                    {
                        return LinkExtensions.ActionLink(htmlHelper, linkText, actionName, controllerName, null, new { disabled = "disabled" });
                    }

                    return new MvcHtmlString(string.Empty);
                }
            }

            return new MvcHtmlString(string.Empty);
        }
    }
}
